﻿//---------------------------------------------------------------------------
// <copyright file="RibbonControlSizeDefinition.cs" company="Microsoft Corporation">
//     Copyright (C) Microsoft Corporation.  All rights reserved.
// </copyright>
//---------------------------------------------------------------------------

namespace Microsoft.Windows.Controls.Ribbon
{
    #region Using declarations

    using System;
    using System.ComponentModel;

    #endregion

    #region RibbonImageSize enum

    /// <summary>
    /// An enumeration of available image sizes.
    /// </summary>
    public enum RibbonImageSize
    {
        /// <summary>
        /// Indicates that a large image should be used. (Usually 32x32 at 96dpi)
        /// </summary>
        Large,

        /// <summary>
        /// Indicates that a small image should be used. (Usually 16x16 at 96dpi)
        /// </summary>
        Small,
    }

    #endregion

    /// <summary>
    /// This class contains information about image size, visibility, and label
    /// visibility for a particular size configuration of a Ribbon control.
    /// </summary>
    public class RibbonControlSizeDefinition : INotifyPropertyChanged
    {
        #region Fields

        /// <summary>
        /// Backing store for the ImageSize property.
        /// </summary>
        private RibbonImageSize _imageSize;

        /// <summary>
        /// Backing store for the IsImageVisible property.
        /// </summary>
        private bool _isImageVisible = true;

        /// <summary>
        /// Backing store for the IsLabelVisible property.
        /// </summary>
        private bool _isLabelVisible = true;

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the RibbonControlSizeDefinition class.  By default
        /// we hook OnPropertyChanged so that we can enforce certain features of the Office
        /// Fluent UI Guidelines. 
        /// </summary>
        public RibbonControlSizeDefinition()
        {
            this.PropertyChanged += new PropertyChangedEventHandler(this.OnPropertyChanged);
        }

        #endregion

        #region Public Events

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets what size the Ribbon control's image should be displayed at.
        /// </summary>
        public RibbonImageSize ImageSize
        {
            get
            {
                return _imageSize;
            }

            set
            {
                if (value != _imageSize)
                {
                    _imageSize = value;
                    this.NotifyPropertyChanged("ImageSize");
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the Ribbon control's image is visible.
        /// </summary>
        public bool IsImageVisible
        {
            get
            {
                return _isImageVisible;
            }

            set
            {
                if (value != _isImageVisible)
                {
                    _isImageVisible = value;
                    this.NotifyPropertyChanged("IsImageVisible");
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the Ribbon control's label is visible.
        /// </summary>
        public bool IsLabelVisible
        {
            get
            {
                return _isLabelVisible;
            }

            set
            {
                if (value != _isLabelVisible)
                {
                    _isLabelVisible = value;
                    this.NotifyPropertyChanged("IsLabelVisible");
                }
            }
        }

        #endregion

        #region Private Methods

        /// <summary>
        /// When the ImageSize or IsLabelVisible properties change, we enforce that if
        /// the control is using a Large ImageSize, that the label is also being shown.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A PropertyChangedEventArgs that contains the event data.</param>
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "ImageSize" || e.PropertyName == "IsLabelVisible")
            {
                if (this.ImageSize == RibbonImageSize.Large && !this.IsLabelVisible)
                {
                    throw new InvalidOperationException("Large controls displayed in the Ribbon must contain text labels.");
                }
            }
        }

        /// <summary>
        /// Raises the PropertyChanged notification for the property with name 'info'.
        /// </summary>
        /// <param name="info">The name of the changed property.</param>
        private void NotifyPropertyChanged(string info)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion
    }
}